import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号


data=pd.read_csv("speed&direction.csv")

'''
#风向频率
wd=data["WD10Avg"]

N=wd[(wd>=348.75) | (wd<11.25)]
NNE=wd[(wd>=11.25) & (wd<33.75)]
NE=wd[(wd>=33.75) & (wd<56.25)]
ENE=wd[(wd>=56.25) & (wd<78.75)]
E=wd[(wd>=78.75) & (wd<101.25)]
ESE=wd[(wd>=101.25) & (wd<123.75)]
SE=wd[(wd>=123.75) & (wd<146.25)]
SSE=wd[(wd>=146.25) & (wd<168.75)]
S=wd[(wd>=168.75) & (wd<191.25)]
SSW=wd[(wd>=191.25) & (wd<213.75)]
SW=wd[(wd>=213.75) & (wd<236.25)]
WSW=wd[(wd>=236.25) & (wd<258.75)]
W=wd[(wd>=258.75) & (wd<281.25)]
WNW=wd[(wd>=281.25) & (wd<303.75)]
NW=wd[(wd>=303.75) & (wd<326.25)]
NNW=wd[(wd>=326.25) & (wd<348.75)]

frequency=[0]*16
l=[N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW]
for i in range(len(l)):
    frequency[i]=len(l[i])/len(wd)

l=['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW']

data={}
for i in range(len(l)):
    data[l[i]]=frequency[i]


label=[  'E', 'ENE','NE', 'NNE', 'N','NNW', 'NW', 'WNW', 'W', 'WSW', 'SW', 'SSW', 'S', 'SSE', 'SE', 'ESE',]


labels = np.array(label) # 标签
dataLenth = 16 # 数据长度

data1 = np.zeros((16))
for i in range(len(label)):
    data1[i]=data[label[i]]



angles = np.linspace(0, 2*np.pi, dataLenth, endpoint=False) # 分割圆周长
data1 = np.concatenate((data1, [data1[0]])) # 闭合

angles = np.concatenate((angles, [angles[0]])) # 闭合

plt.polar(angles, data1, '-', linewidth=1) #做极坐标系
plt.fill(angles, data1, alpha=0.25)# 填充


plt.thetagrids(angles * 180/np.pi, labels=labels,fontsize=14) # 设置网格、标签

plt.title("10m高度风向频率玫瑰图",fontsize=18)

#plt.ylim(0,0.14)  # polar的极值设置为ylim

plt.show()
'''

wd=data["WD10Avg"]

N=data[(wd>=348.75) | (wd<11.25)]["WS10Avg"]
NNE=data[(wd>=11.25) & (wd<33.75)]["WS10Avg"]
NE=data[(wd>=33.75) & (wd<56.25)]["WS10Avg"]
ENE=data[(wd>=56.25) & (wd<78.75)]["WS10Avg"]
E=data[(wd>=78.75) & (wd<101.25)]["WS10Avg"]
ESE=data[(wd>=101.25) & (wd<123.75)]["WS10Avg"]
SE=data[(wd>=123.75) & (wd<146.25)]["WS10Avg"]
SSE=data[(wd>=146.25) & (wd<168.75)]["WS10Avg"]
S=data[(wd>=168.75) & (wd<191.25)]["WS10Avg"]
SSW=data[(wd>=191.25) & (wd<213.75)]["WS10Avg"]
SW=data[(wd>=213.75) & (wd<236.25)]["WS10Avg"]
WSW=data[(wd>=236.25) & (wd<258.75)]["WS10Avg"]
W=data[(wd>=258.75) & (wd<281.25)]["WS10Avg"]
WNW=data[(wd>=281.25) & (wd<303.75)]["WS10Avg"]
NW=data[(wd>=303.75) & (wd<326.25)]["WS10Avg"]
NNW=data[(wd>=326.25) & (wd<348.75)]["WS10Avg"]



l=[N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW]
frequency=[0]*16


for i in range(len(l)):
    frequency[i]=sum(l[i]**3)/sum(data["WS10Avg"]**3)



l=['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW']

data={}
for i in range(len(l)):
    data[l[i]]=frequency[i]


label=[  'E', 'ENE','NE', 'NNE', 'N','NNW', 'NW', 'WNW', 'W', 'WSW', 'SW', 'SSW', 'S', 'SSE', 'SE', 'ESE',]


labels = np.array(label) # 标签
dataLenth = 16 # 数据长度

data1 = np.zeros((16))
for i in range(len(label)):
    data1[i]=data[label[i]]



angles = np.linspace(0, 2*np.pi, dataLenth, endpoint=False) # 分割圆周长
data1 = np.concatenate((data1, [data1[0]])) # 闭合

angles = np.concatenate((angles, [angles[0]])) # 闭合

plt.polar(angles, data1, '-', linewidth=1,color='r') #做极坐标系
plt.fill(angles, data1, alpha=0.25,color='r')# 填充


plt.thetagrids(angles * 180/np.pi, labels=labels,fontsize=14) # 设置网格、标签

plt.title("10m高度风能频率玫瑰图",fontsize=18)

#plt.ylim(0,0.14)  # polar的极值设置为ylim

plt.show()



